﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ReconCaracteres_Backpropagation
{
    public partial class CreateFileWithAllPattens : Form
    {
        public Sample selectedSample;
        public CreateFileWithAllPattens()
        {
            InitializeComponent();
            this.pictureBoxSign.Size = new System.Drawing.Size(100, 100);
            this.IDlabel.Text = "";
        }

        private void classifyButton_Click(object sender, EventArgs e)
        {

        }

        private void loadSamplebutton_Click(object sender, EventArgs e)
        {
            openFileDialog.ShowDialog();


            selectedSample = new Sample(openFileDialog.FileName);



            this.IDlabel.Text = selectedSample.ID;
            this.pictureBoxSign.Image = selectedSample.getBitmap();
            pictureBoxSign.SizeMode = PictureBoxSizeMode.StretchImage;
        }

        private void CreateFileWithAllPattens_Load(object sender, EventArgs e)
        {

        }

        private void AgregarButton_Click(object sender, EventArgs e)
        {
            if (this.categoriesSetcomboBox.SelectedItem == null || this.selectedSample == null)
            {
                MessageBox.Show("Seleccione una categoría/muestra");
                return;
            }
            selectedSample.category = this.categoriesSetcomboBox.SelectedItem.ToString();
            selectedSample.categoryIndex = Int32.Parse(this.categoriesSetcomboBox.SelectedIndex.ToString());
          //  this.selectedSample.setExpectedVector(this.categoriesSetcomboBox.SelectedIndex, this.categoriesSetcomboBox.Items.Count);
            this.SamplesSetlistBox.Items.Add(this.selectedSample);
    
        }

        private void CreateFileButton_Click(object sender, EventArgs e)
        {
            saveFileDialog.Title = "Guardar archivo con todas las muestras";
            saveFileDialog.ShowDialog();


            if (saveFileDialog.FileName != "")
            {
                MyFile myFile = new MyFile(saveFileDialog.FileName);
                for (int i = 0; i < this.SamplesSetlistBox.Items.Count; i++)
                {
                    //myFile.writeSeparator(((Sample)this.SamplesSetlistBox.Items[i]).categoryIndex);
                    if (0 != i)
                    {
                        myFile.file.WriteLine("");
                    }
                    myFile.file.WriteLine("[" + ((Sample)this.SamplesSetlistBox.Items[i]).categoryIndex + "]");
                    myFile.writeMatrix(((Sample)this.SamplesSetlistBox.Items[i]).matrix);

                }
                myFile.close();
                MessageBox.Show("Archivo guardado exitosamente");
            }
        }
    }
}
